//
//  LFExceptionController.m
//  ServiceBaZhou
//
//  Created by 刘江涛 on 2017/8/24.
//  Copyright © 2017年 weierda. All rights reserved.
//

#import "LFExceptionController.h"

#import "CFToolUtil.h"

#import "ExceptionModel.h"

@interface LFExceptionController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSMutableArray *dataArray;

@property (nonatomic,copy) NSString *titleStr;

@property (nonatomic,copy) NSString *contentStr;

@end

@implementation LFExceptionController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _titleStr = @"移出经营异常名录原因\n2016-08-03";
    
    _contentStr = @"列入经营异常名录3年内且依据经营异常名录管理办法第六条规定别列入经营异常名录的企业，可以在不饱未报年份的年度报告并公示后，申请移出";
    
    [self createNavigation:@"经营异常"];
    
    [self createTableView];
    
    [self loadData];
}

- (void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, Width, Height - 64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
}

- (void)loadData{
    NSMutableDictionary *para = [NSMutableDictionary dictionaryWithCapacity:0];
    [para setObject:Token forKey:@"key"];
    [para setObject:_keyNo forKey:@"keyNo"];
    
    [CFHttpTools getRequest:@"ECIException/GetOpException" params:para success:^(id responseObj) {
        //
        CFLog(@"%@",responseObj);
        
        if(![responseObj[@"Result"] isKindOfClass:[NSArray class]]){
            if([CFToolUtil isBlankString:responseObj[@"Result"]]){
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 64, Width - 100 , Width - 100)];
                imageView.image = [UIImage imageNamed:@"nodata"];
                [self.tableView addSubview:imageView];
                
                UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, Width - 20, Width, 20)];
                label.text = @"暂无数据";
                label.textColor = [UIColor grayColor];
                label.textAlignment = NSTextAlignmentCenter;
                [self.tableView addSubview:label];
            }
        }else{
            
            NSArray *exceptionArray = responseObj[@"Result"];
            
            JSONModelArray *modelArray = [[JSONModelArray alloc]initWithArray:exceptionArray modelClass:[ExceptionModel class]];
            
            self.dataArray = [NSMutableArray array];
            
            [self.dataArray addObjectsFromArray:(NSArray *)modelArray];
            
            [_tableView reloadData];
        }
        
    } failure:^(NSError *error) {
        //
        NSLog(@"%@",error.localizedDescription);
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ExceptionModel *model = _dataArray[indexPath.section];
    if(indexPath.row == 0){
        return [CFToolUtil getLabelHeightWith:model.RomoveReason AndStrSize:12.0 AndLabelWith:Width-50] + 50;
    }else if (indexPath.row == 1){
        return [CFToolUtil getLabelHeightWith:model.AddReason AndStrSize:10.0 AndLabelWith:Width-50] + 50;
    }else{
        return 50;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ExceptionModel *model = _dataArray[indexPath.section];
    
    static NSString *iden = @"iden";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:iden];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if(indexPath.row == 0){
        cell.textLabel.text = [NSString stringWithFormat:@"移出经营异常名录原因\n%@",[model.RemoveDate substringToIndex:10]];
    }else if (indexPath.row == 1){
        cell.textLabel.text = [NSString stringWithFormat:@"列入经营异常名录原因\n%@",[model.AddDate substringToIndex:10]];
    }else{
        cell.textLabel.text = @"作出决定机关";
    }
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#A1A1A1"];
    cell.textLabel.font = [UIFont systemFontOfSize:10];
    cell.textLabel.numberOfLines = 0;
    
    if(indexPath.row == 0){
        if([CFToolUtil isBlankString:model.RomoveReason]){
            cell.detailTextLabel.text = @"尚未移出";
        }else{
            cell.detailTextLabel.text = model.RomoveReason;
        }
    }else if (indexPath.row == 1){
        cell.detailTextLabel.text = model.AddReason;
    }else{
        cell.detailTextLabel.text = model.DecisionOffice;
    }
    cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
    cell.detailTextLabel.numberOfLines = 0;
    
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
